import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jinke/page/pro_list/subs/pro_detail/main/widgets/header.dart';
import 'package:jinke/page/pro_list/subs/pro_detail/subs/pro_base_info/index.dart';
import 'package:jinke/page/pro_list/subs/pro_detail/subs/pro_instruction/index.dart';
import 'package:jinke/page/pro_list/subs/pro_detail/subs/pro_inventory/index.dart';
import 'package:jinke/page/pro_list/subs/pro_detail/subs/pro_progress/index.dart';
import 'package:jinke/page/pro_list/subs/pro_detail/subs/pro_progress_day/index.dart';
import 'package:jinke/page/pro_list/subs/pro_detail/subs/pro_question_exsit/index.dart';
import 'package:jinke/utils/component/component.dart';
import 'package:jinke/utils/component/tp_tabbar.dart';
import 'package:jinke/utils/util.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class ProDetailPage extends GetView<ProDetailController> {
  const ProDetailPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    var state = controller.state;
    return NestedScrollView(
        headerSliverBuilder: ((context, innerBoxIsScrolled) {
          return [
            const SliverToBoxAdapter(
              child: ProTitleWidget(),
            ),
            SliverPersistentHeader(
              pinned: true,
              floating: true,
              delegate: TPSliverPersistentHeaderDelegate(
                  child: Container(
                    color: Colors.white,
                    height: 50.r,
                    child: TPTabBar(
                        tabCtrl: state.tabCtrl, tabTitles: state.tabTitles),
                  ),
                  max: 50.r,
                  min: 50.r),
            ),
          ];
        }),
        body: TabBarView(controller: state.tabCtrl, children: [
          ProBaseInfoPage(
            mod: state.detailMod,
            enterprise: state.enterpriseMod,
          ),
          ProProgressPage(list: state.phaseList),
          ProProgressDayPage(
            mod: state.detailMod,
          ),
          ProInventoryPage(
            mod: state.detailMod,
          ),
          ProInstructionPage(state.detailMod?.id ?? ''),
          ProQuestionExsitPage(
            mod: state.detailMod,
          ),
        ]));
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ProDetailController>(
      builder: (_) {
        return Scaffold(
          appBar: detailAppBar(context, title: '项目详情'),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
